package com.forestar.mapControl.utils.mapConvert.geometry.utils;

import com.forestar.mapControl.utils.mapConvert.geometry.Envelope;
import com.forestar.mapControl.utils.mapConvert.geometry.GeoLine;
import com.forestar.mapControl.utils.mapConvert.geometry.GeoMultiLine;
import com.forestar.mapControl.utils.mapConvert.geometry.GeoMultiPoint;
import com.forestar.mapControl.utils.mapConvert.geometry.GeoMultiPolygon;
import com.forestar.mapControl.utils.mapConvert.geometry.GeoPoint;
import com.forestar.mapControl.utils.mapConvert.geometry.GeoPolygon;
import com.forestar.mapControl.utils.mapConvert.geometry.IGeometry;
import com.forestar.mapControl.utils.mapConvert.geometry.coordinatesystem.CoordinateSystem;
import com.mapzone.api.geometry.mzEnvelope;
import com.mapzone.api.geometry.mzGeoClip;
import com.mapzone.api.geometry.mzGeoExtract;
import com.mapzone.api.geometry.mzGeometry;
import com.mapzone.api.geometry.mzLabelPosition;
import com.mapzone.api.geometry.mzMultiLineString;
import com.mapzone.api.geometry.mzMultiPoint;
import com.mapzone.api.geometry.mzMultiPolygon;
import com.mapzone.api.geometry.mzPath;
import com.mapzone.api.geometry.mzPoint;
import com.mapzone.api.geometry.mzPolygon;


public class GeometryUtils
  {
    public static final float DEG2RAD = (float) (Math.PI / 180.0);
    public static final float RAD2DEG = (float) (180.0 / Math.PI);
    public static final float PI = (float) Math.PI;
    public static final int RADIUS_EARTH_METERS = 6378137;
    //public static final mzLabelPosition m_mzLabelPosition = new mzLabelPosition();

    public static GeoPoint getLabelPoint(IGeometry geometry, mzLabelPosition labelPosition)
      {
        switch (geometry.getGeometryType())
          {
            case GeometryTypePoint:
              return getLabelPointOfGeoPoint((GeoPoint) geometry, labelPosition);
            case GeometryTypeMultiPoint:
              return getLabelPointOfGeoMultiPoint((GeoMultiPoint) geometry, labelPosition);
            case GeometryTypePolyline:
              return getLabelPointOfGeoLine((GeoLine) geometry, labelPosition);
            case GeometryTypeMultiPolyline:
              return getLabelPointOfGeoMultiLine((GeoMultiLine) geometry, labelPosition);
            case GeometryTypePolygon:
              return getLabelPointOfGeoPolygon((GeoPolygon) geometry, labelPosition);
            case GeometryTypeMultiPolygon:
              return getLabelPointOfGeoMultiPolygon((GeoMultiPolygon) geometry, labelPosition);
            case GeometryTypeUnknown:
              return null;
          }
        return null;
      }

    private static GeoPoint getLabelPointOfGeoPoint(GeoPoint geoPoint, mzLabelPosition labelPosition)
      {
        return geoPoint;
      }

    private static GeoPoint getLabelPointOfGeoMultiPoint(GeoMultiPoint multiPoint, mzLabelPosition labelPosition)
      {
        //获取mzGeometry
        Object obj = multiPoint.getInternalObject();
        GeoPoint geoPoint = new GeoPoint(multiPoint.getCoordinateSystem(), 0.0, 0.0);
        if (obj instanceof mzMultiPoint)
          {
            mzMultiPoint m_mzMultiPoint = (mzMultiPoint) obj;
            mzPoint m_mzLabelPoint = labelPosition.GetLabelPoint(m_mzMultiPoint);
            geoPoint.setX(m_mzLabelPoint.getX());
            geoPoint.setY(m_mzLabelPoint.getY());
          }
        return geoPoint;
      }

    private static GeoPoint getLabelPointOfGeoLine(GeoLine line, mzLabelPosition labelPosition)
      {
        //获取mzGeometry
        Object obj = line.getInternalObject();
        GeoPoint geoPoint = new GeoPoint(line.getCoordinateSystem(), 0.0, 0.0);
        if (obj instanceof mzPath)
          {
            mzPath m_mzPath = (mzPath) obj;
            mzPoint m_mzLabelPoint = labelPosition.GetLabelPoint(m_mzPath);
            geoPoint.setX(m_mzLabelPoint.getX());
            geoPoint.setY(m_mzLabelPoint.getY());
          }
        return geoPoint;
      }

    private static GeoPoint getLabelPointOfGeoMultiLine(GeoMultiLine multiLine, mzLabelPosition labelPosition)
      {
        //获取mzGeometry
        Object obj = multiLine.getInternalObject();
        GeoPoint geoPoint = new GeoPoint(multiLine.getCoordinateSystem(), 0.0, 0.0);
        if (obj instanceof mzMultiLineString)
          {
            mzMultiLineString m_mzMultiLineString = (mzMultiLineString) obj;
            mzPoint m_mzLabelPoint = labelPosition.GetLabelPoint(m_mzMultiLineString);
            geoPoint.setX(m_mzLabelPoint.getX());
            geoPoint.setY(m_mzLabelPoint.getY());
          }
        return geoPoint;
      }

    private static GeoPoint getLabelPointOfGeoPolygon(GeoPolygon polygon, mzLabelPosition labelPosition)
      {
        //设置扫描参数
        labelPosition.SetScanMethod(mzLabelPosition.scanModeBoth, 1.0, 0.1);
        //获取mzGeometry
        Object obj = polygon.getInternalObject();
        GeoPoint geoPoint = new GeoPoint(polygon.getCoordinateSystem(), 0.0, 0.0);
        if (obj instanceof mzPolygon)
          {
            mzPolygon m_mzPolygon = (mzPolygon) obj;
            mzPoint m_mzLabelPoint = labelPosition.GetLabelPoint(m_mzPolygon);
            geoPoint.setX(m_mzLabelPoint.getX());
            geoPoint.setY(m_mzLabelPoint.getY());
          }
        return geoPoint;
      }

    private static GeoPoint getLabelPointOfGeoMultiPolygon(GeoMultiPolygon multiPolygon, mzLabelPosition labelPosition)
      {
        //设置扫描参数
        labelPosition.SetScanMethod(mzLabelPosition.scanModeBoth, 1.0, 0.1);
        //获取mzGeometry
        Object obj = multiPolygon.getInternalObject();
        GeoPoint geoPoint = new GeoPoint(multiPolygon.getCoordinateSystem(), 0.0, 0.0);
        if (obj instanceof mzMultiPolygon)
          {
            mzMultiPolygon m_mzMultiPolygon = (mzMultiPolygon) obj;
            mzPoint m_mzLabelPoint = labelPosition.GetLabelPoint(m_mzMultiPolygon);
            geoPoint.setX(m_mzLabelPoint.getX());
            geoPoint.setY(m_mzLabelPoint.getY());
          }
        return geoPoint;
      }

//    /**
//     * @param geometry
//     * @param symbol   参数的设计是为考虑符号对元素的影响，比如点符号有很大的半径，那么整个符号区域，都应该可以选择
//     * @return
//     */
//    public static Envelope getEnvelopeWithSymbol(IGeometry geometry, ISymbol symbol)
//      {
//        Envelope env = geometry.getEnvelope();
//        return env;
//      }

    public static boolean intersect(Envelope envSrc, Envelope envelope)
      {
        if (envSrc.intersect(envelope))
          {
            return true;
          }
        return false;
      }

    public static Envelope getEnvelope(mzGeometry geometry)
      {
        mzEnvelope env = geometry.GetEnvelope();
        return new Envelope(CoordinateSystem.create(geometry.getSrid()), env.getXMin(), env.getXMax(), env.getYMin(), env.getYMax());
      }

//    public static void geoMultiPolygonToPath(Path pathReUse, Path borderPath, float borderWidth, GeoMultiPolygon polygon, MapViewTransform referBorderMapViewTransform, MapViewTransform currentMapViewTransform)
//      {
//        Object obj = polygon.getInternalObject();
//        if (obj instanceof mzMultiPolygon)
//          {
//            mzMultiPolygon internalPolygon = (mzMultiPolygon) obj;
//            int count = internalPolygon.getPolygonCount();
//            for (int i = 0; i < count; i++)
//              {
//                mzPolygonToPath(pathReUse, borderPath, borderWidth, internalPolygon.GetPolygon(i), referBorderMapViewTransform, currentMapViewTransform);
//              }
//          } else if (obj instanceof MultiPolygon)
//          {
//            MultiPolygon py = (MultiPolygon) obj;
//            int count = py.getPolygons().size();
//            for (int i = 0; i < count; i++)
//              {
//                geoJSONPolygonToPath(pathReUse, py.getPolygons().get(i), referBorderMapViewTransform, polygon.getCoordinateSystem());
//              }
//          }
//      }
//
//    public static void geoPolygonToPath(Path pathReUse, Path borderPath, float borderWidth, GeoPolygon polygon, MapViewTransform referBorderMapViewTransform, MapViewTransform currentMapViewTransform)
//      {
//        Object obj = polygon.getInternalObject();
//        if (obj instanceof mzPolygon)
//          {
//            mzPolygon internalPolygon = (mzPolygon) obj;
//            mzPolygonToPath(pathReUse, borderPath, borderWidth, internalPolygon, referBorderMapViewTransform, currentMapViewTransform);
//          } else if (obj instanceof Polygon)
//          {
//            Polygon py = (Polygon) obj;
//            geoJSONPolygonToPath(pathReUse, py, referBorderMapViewTransform, polygon.getCoordinateSystem());
//          }
//      }

//    private static void mzPolygonToPath(Path pathReUse, Path borderPath, float borderWidth, mzPolygon polygon, MapViewTransform referBorderMapViewTransform, MapViewTransform currentMapViewTransform)
//      {
//        // 添加外环
//        mzRing exteriorRing = polygon.GetExteriorRing();
//        Path[] paths = mzRingToPath(exteriorRing, referBorderMapViewTransform, currentMapViewTransform, borderWidth);
//        pathReUse.addPath(paths[0]);
//        if (borderPath != null)
//          {
//            borderPath.addPath(paths[1]);
//          }
//        // 添加内环
//        mzRing innerRing;
//        for (int i = 0; i < polygon.getInnerRingCount(); i++)
//          {
//            innerRing = polygon.GetInnerRing(i);
//            paths = mzRingToPath(innerRing, referBorderMapViewTransform, currentMapViewTransform, borderWidth);
//            pathReUse.addPath(paths[0]);
//            if (borderPath != null)
//              {
//                borderPath.addPath(paths[1]);
//              }
//          }
//      }

//    /**
//     *
//     * @param ring
//     * @param referBorderMapViewTransform
//     * @param currentMapViewTransform
//     * @param borderWidth
//     * @return
//     */
//    private static Path[] mzRingToPath(mzRing ring, MapViewTransform referBorderMapViewTransform, MapViewTransform currentMapViewTransform, float borderWidth)
//      {
//        MapViewTransform mt = currentMapViewTransform.clone();
//        double[] points = ring.GetPoints();
//        float[] screenPoints = mt.mapPoints2ScreenPoints(points);
//        Rect referBorder;
//        Rect currentBoder = currentMapViewTransform.getViewRect();
//        if (null == referBorderMapViewTransform)
//          {
//            referBorder = currentBoder;
//          } else
//          {
//            Envelope envelope = referBorderMapViewTransform.getViewBound();
//            float[] lt = mt.mapPoints2ScreenPoints(new double[]{envelope.getXMin(), envelope.getYMin()});
//            float[] rb = mt.mapPoints2ScreenPoints(new double[]{envelope.getXMax(), envelope.getYMax()});
//            referBorder = new Rect(Math.max(currentBoder.left, (int) lt[0]), Math.max(currentBoder.top, (int) rb[1]), Math.min(currentBoder.right, (int) rb[0]), Math.min(currentBoder.bottom, (int) lt[1]));
//          }
//        return DrawSketch.buildPath(screenPoints, !ring.getIsClosed(), referBorder, borderWidth);
//      }

//    private static void geoJSONPolygonToPath(Path pathReUse, Polygon polygon, MapViewTransform mapViewTransform, CoordinateSystem coordSystem)
//      {
//        int rings = polygon.getRings().size();
//        for (int i = 0; i < rings; i++)
//          {
//            Ring r = polygon.getRings().get(i);
//            pathReUse.addPath(geoJSONRingToPath(r, coordSystem, mapViewTransform));
//          }
//      }

//    private static Path geoJSONRingToPath(Ring ring, CoordinateSystem coordinateSystem, MapViewTransform mapViewTransform)
//      {
//        MapViewTransform mt = mapViewTransform.clone();
//        double[] pointTemp = new double[2];
//        double[] points = new double[ring.getPositions().size() * 2];
//        for (int i = 0; i < ring.getPositions().size(); i++)
//          {
//            pointTemp[0] = ring.getPositions().get(i).getLongitude();
//            pointTemp[1] = ring.getPositions().get(i).getLatitude();
//            CoordinateSystem.projectPoint(coordinateSystem, mapViewTransform.getCoordinateSystem(), pointTemp);
//            points[2 * i] = pointTemp[0];
//            points[2 * i + 1] = pointTemp[1];
//          }
//        float[] screenPoints = mt.mapPoints2ScreenPoints(points);
//        return DrawSketch.buildPath(screenPoints, true);
//      }

    public static double distanceTo(GeoPoint lonLatPoint1, GeoPoint lonLatPoint2)
      {
        final double a1 = DEG2RAD * lonLatPoint1.getY();
        final double a2 = DEG2RAD * lonLatPoint1.getX();
        final double b1 = DEG2RAD * lonLatPoint2.getY();
        final double b2 = DEG2RAD * lonLatPoint2.getX();
        final double cosa1 = Math.cos(a1);
        final double cosb1 = Math.cos(b1);
        final double t1 = cosa1 * Math.cos(a2) * cosb1 * Math.cos(b2);
        final double t2 = cosa1 * Math.sin(a2) * cosb1 * Math.sin(b2);
        final double t3 = Math.sin(a1) * Math.sin(b1);
        final double tt = Math.acos(t1 + t2 + t3);
        return RADIUS_EARTH_METERS * tt;
      }

    public static GeoPoint getPointWithGeographicCoordinateSystem(GeoPoint point)
      {
        GeoPoint outPoint = new GeoPoint(point.getCoordinateSystem().getGeographicCoordinateSystem(), 0, 0);
        CoordinateSystem.projectPoint(point, outPoint);
        return outPoint;
      }

    public static void extractPolyline(IGeometry subjGeo, double dResolution, double dThresholdVal)
      {
        GeoLine subjGeoLine = (GeoLine) subjGeo;
        Object obj = subjGeoLine.getInternalObject();
        // zdb几何体
        if (obj instanceof mzPath)
          {
            mzPath subjmzPath = (mzPath) obj;
            mzGeoExtract.geoExtract(subjmzPath, dResolution, dThresholdVal);
          }
      }

    public static void extractMultiPolyline(IGeometry subjGeo, double dResolution, double dThresholdVal)
      {
        GeoMultiLine subjGeoLine = (GeoMultiLine) subjGeo;
        Object obj = subjGeoLine.getInternalObject();
        // zdb几何体
        if (obj instanceof mzMultiLineString)
          {
            mzMultiLineString subjmzMultiLineString = (mzMultiLineString) obj;
            mzGeoExtract.geoExtract(subjmzMultiLineString, dResolution, dThresholdVal);
          }
      }

    public static void extractPolygon(IGeometry subjGeo, double dResolution, double dThresholdVal)
      {
        GeoPolygon subjGeoLine = (GeoPolygon) subjGeo;
        Object obj = subjGeoLine.getInternalObject();
        // zdb几何体
        if (obj instanceof mzPolygon)
          {
            mzPolygon subjmzPolygon = (mzPolygon) obj;
            mzGeoExtract.geoExtract(subjmzPolygon, dResolution, dThresholdVal);
          }
//        // JSON几何体
//        else if (obj instanceof Polygon)
//          {
//            // TODO
//          }
      }

    public static void extractMultiPolygon(IGeometry subjGeo, double dResolution, double dThresholdVal)
      {
        GeoMultiPolygon subjGeoLine = (GeoMultiPolygon) subjGeo;
        Object obj = subjGeoLine.getInternalObject();
        // zdb几何体
        if (obj instanceof mzMultiPolygon)
          {
            mzMultiPolygon subjmzMultiPolygon = (mzMultiPolygon) obj;
            mzGeoExtract.geoExtract(subjmzMultiPolygon, dResolution, dThresholdVal);
          }
//        // JSON几何体
//        else if (obj instanceof Polygon)
//          {
//            // TODO
//          }
      }

    public static IGeometry clipPolygon(IGeometry subjGeo, Envelope clipEnv)
      {
        GeoPolygon subjGeoPolygon = (GeoPolygon) subjGeo;
        Object obj = subjGeoPolygon.getInternalObject();
        // 1)构建裁剪矩形框
        mzEnvelope clipmzEnv = new mzEnvelope();
        clipmzEnv.setXMin(clipEnv.getXMin());
        clipmzEnv.setYMin(clipEnv.getYMin());
        clipmzEnv.setXMax(clipEnv.getXMax());
        clipmzEnv.setYMax(clipEnv.getYMax());
        // zdb几何体
        if (obj instanceof mzPolygon)
          {
            mzPolygon subjmzPolygon = (mzPolygon) obj;
            mzGeometry clipmzGeo = mzGeoClip.geoClip(subjmzPolygon, clipmzEnv);
            clipmzEnv.dispose();
            if (clipmzGeo == null)
              {
                return null;
              }
            // 裁剪结果为简单多边形
            if (clipmzGeo.getGeometryType() == mzGeometry.mzGeometryPolygon)
              {
                mzPolygon clipmzPolygon = (mzPolygon) (clipmzGeo);
                GeoPolygon clipGeoPolyogn = new GeoPolygon(subjGeoPolygon.getCoordinateSystem(), clipmzPolygon);
                return clipGeoPolyogn;
              }
            // 裁剪结果为复杂多边形
            else if (clipmzGeo.getGeometryType() == mzGeometry.mzGeometryMultiPolygon)
              {
                mzMultiPolygon clipmzMultiPolygon = (mzMultiPolygon) (clipmzGeo);
                GeoMultiPolygon clipGeoMultiPolyogn = new GeoMultiPolygon(subjGeoPolygon.getCoordinateSystem(), clipmzMultiPolygon);
                return clipGeoMultiPolyogn;
              }
          }
//        // JSON几何体
//        else if (obj instanceof Polygon)
//          {
//            // TODO
//          }
        return null;
      }

    public static IGeometry clipMultiPolygon(IGeometry subjGeo, Envelope clipEnv)
      {
        GeoMultiPolygon subjGeoMultiPolygon = (GeoMultiPolygon) subjGeo;
        Object obj = subjGeoMultiPolygon.getInternalObject();
        // 1)构建裁剪矩形框
        mzEnvelope clipmzEnv = new mzEnvelope();
        clipmzEnv.setXMin(clipEnv.getXMin());
        clipmzEnv.setYMin(clipEnv.getYMin());
        clipmzEnv.setXMax(clipEnv.getXMax());
        clipmzEnv.setYMax(clipEnv.getYMax());
        // zdb几何体
        if (obj instanceof mzMultiPolygon)
          {
            mzMultiPolygon subjmzMultiPolygon = (mzMultiPolygon) obj;
            mzGeometry clipmzGeo = mzGeoClip.geoClip((mzGeometry) subjmzMultiPolygon, (mzGeometry) clipmzEnv);
            if (clipmzGeo == null)
              {
                subjGeo = null;
                return null;
              }
            // 裁剪结果为简单多边形
            if (clipmzGeo.getGeometryType() == mzGeometry.mzGeometryPolygon)
              {
                mzPolygon clipmzPolygon = (mzPolygon) (clipmzGeo);
                GeoPolygon clipGeoPolyogn = new GeoPolygon(subjGeoMultiPolygon.getCoordinateSystem(), clipmzPolygon);
                return clipGeoPolyogn;
              }
            // 裁剪结果为复杂多边形
            else if (clipmzGeo.getGeometryType() == mzGeometry.mzGeometryMultiPolygon)
              {
                mzMultiPolygon clipmzMultiPolygon = (mzMultiPolygon) (clipmzGeo);
                GeoMultiPolygon clipGeoMultiPolyogn = new GeoMultiPolygon(subjGeoMultiPolygon.getCoordinateSystem(), clipmzMultiPolygon);
                return clipGeoMultiPolyogn;
              }
          }
//        // JSON几何体
//        else if (obj instanceof MultiPolygon)
//          {
//            // TODO
//          }
        return null;
      }

    public static IGeometry mzGeometry2IGeometry(mzGeometry m_mzGeometry)
      {
        if (null == m_mzGeometry)
          return null;
        int nGeoType = m_mzGeometry.getGeometryType();
        IGeometry geometry = null;
        switch (nGeoType)
          {
            // 几何为空
            case mzGeometry.mzGeometryNull:
              break;
            // 单点
            case mzGeometry.mzGeometryPoint:
              geometry = new GeoPoint(CoordinateSystem.create(m_mzGeometry.getSrid()), (mzPoint) m_mzGeometry);
              break;
            // 多点
            case mzGeometry.mzGeometryMultiPoint:
              geometry = new GeoMultiPoint(CoordinateSystem.create(m_mzGeometry.getSrid()), (mzMultiPoint) m_mzGeometry);
              break;
            // 连续线/混合
            case mzGeometry.mzGeometryPath:
              geometry = new GeoLine(CoordinateSystem.create(m_mzGeometry.getSrid()), (mzPath) m_mzGeometry);
              break;
            // 环(Ring)
            case mzGeometry.mzGeometryRing:
              break;
            // 多段线
            case mzGeometry.mzGeometryMultiPath:
              geometry = new GeoMultiLine(CoordinateSystem.create(m_mzGeometry.getSrid()), (mzMultiLineString) m_mzGeometry);
              break;
            // 单面
            case mzGeometry.mzGeometryPolygon:
              geometry = new GeoPolygon(CoordinateSystem.create(m_mzGeometry.getSrid()), (mzPolygon) m_mzGeometry);
              break;
            // 多面
            case mzGeometry.mzGeometryMultiPolygon:
              geometry = new GeoMultiPolygon(CoordinateSystem.create(m_mzGeometry.getSrid()), (mzMultiPolygon) m_mzGeometry);
              break;
            // 正矩形(Eenvelope)
            case mzGeometry.mzGeometryEnvelope:
              break;
            // 默认情况
            default:
              break;
          }
        return geometry;
      }

    public static IGeometry clipLine(IGeometry subjGeo, Envelope clipEnv)
      {
        GeoLine subjGeoLine = (GeoLine) subjGeo;
        Object obj = subjGeoLine.getInternalObject();
        // 1)构建裁剪矩形框
        mzEnvelope clipmzEnv = new mzEnvelope();
        clipmzEnv.setXMin(clipEnv.getXMin());
        clipmzEnv.setYMin(clipEnv.getYMin());
        clipmzEnv.setXMax(clipEnv.getXMax());
        clipmzEnv.setYMax(clipEnv.getYMax());
        // zdb几何体
        if (obj instanceof mzPath)
          {
            mzPath subjmzPath = (mzPath) obj;
            mzGeometry clipmzGeo = mzGeoClip.geoClip((mzGeometry) subjmzPath, (mzGeometry) clipmzEnv);
            if (clipmzGeo == null)
              {
                subjGeo = null;
                return null;
              }
            clipmzGeo.setSrid(subjmzPath.getSrid());
            // 裁剪结果为简单线
            if (clipmzGeo.getGeometryType() == mzGeometry.mzGeometryPath)
              {
                mzPath clipmzPath = (mzPath) (clipmzGeo);
                GeoLine clipGeoLine = new GeoLine(subjGeoLine.getCoordinateSystem(), clipmzPath);
                return clipGeoLine;
              }
            //裁剪结果为复杂线
            else if (clipmzGeo.getGeometryType() == mzGeometry.mzGeometryMultiPath)
              {
                mzMultiLineString clipmzMultiLineString = (mzMultiLineString) (clipmzGeo);
                GeoMultiLine clipGeoMultiLine = new GeoMultiLine(subjGeoLine.getCoordinateSystem(), clipmzMultiLineString);
                return clipGeoMultiLine;
              }
          }
        return null;
      }

    public static IGeometry clipMultiLine(IGeometry subjGeo, Envelope clipEnv)
      {
        GeoMultiLine subjGeoMultiLine = (GeoMultiLine) subjGeo;
        Object obj = subjGeoMultiLine.getInternalObject();
        // 1)构建裁剪矩形框
        mzEnvelope clipmzEnv = new mzEnvelope();
        clipmzEnv.setXMin(clipEnv.getXMin());
        clipmzEnv.setYMin(clipEnv.getYMin());
        clipmzEnv.setXMax(clipEnv.getXMax());
        clipmzEnv.setYMax(clipEnv.getYMax());
        // zdb几何体
        if (obj instanceof mzMultiLineString)
          {
            mzMultiLineString subjmzMultiLineString = (mzMultiLineString) obj;
            mzGeometry clipmzGeo = mzGeoClip.geoClip((mzGeometry) subjmzMultiLineString, (mzGeometry) clipmzEnv);
            if (clipmzGeo == null)
              {
                subjGeo = null;
                return null;
              }
            clipmzGeo.setSrid(subjmzMultiLineString.getSrid());
            // 裁剪结果为简单线
            if (clipmzGeo.getGeometryType() == mzGeometry.mzGeometryPath)
              {
                mzPath clipmzPath = (mzPath) (clipmzGeo);
                GeoLine clipGeoLine = new GeoLine(subjGeoMultiLine.getCoordinateSystem(), clipmzPath);
                return clipGeoLine;
              }
            //裁剪结果为复杂线
            else if (clipmzGeo.getGeometryType() == mzGeometry.mzGeometryMultiPath)
              {
                mzMultiLineString clipmzMultiLineString = (mzMultiLineString) (clipmzGeo);
                GeoMultiLine clipGeoMultiLine = new GeoMultiLine(subjGeoMultiLine.getCoordinateSystem(), clipmzMultiLineString);
                return clipGeoMultiLine;
              }
          }
        return null;
      }

    public static GeoMultiLine geoLine2GeoMultiLine(GeoLine geoLine)
      {
        mzPath m_mzPath = (mzPath) geoLine.getInternalObject();
        mzPath m_mzPathClone = (mzPath) m_mzPath.clone();
        mzMultiLineString m_mzMultiLineString = new mzMultiLineString();
        m_mzMultiLineString.AddPath(m_mzPathClone);
        return new GeoMultiLine(geoLine.getCoordinateSystem(), m_mzMultiLineString);
      }
  }